﻿
@{
    Layout = "";
}
<style>
    .ngdialog.ngdialog-theme-plain .ngdialog-content {
        width: 60% !important;
    }
</style>
<div ng-controller="ProductCommentController">
    <h3>评论管理</h3>

    <div class="panel panel-default" ng-class="{ 'whirl standard': isLoading}">
        <div class="panel-heading">
            <div class="form-inline ng-pristine ng-valid">
                <div class="form-group">
                    <input placeholder="会员名、产品编号、产品名" class="form-control " type="text" ng-model="Keywords">
                    <input placeholder="IP" class="form-control " type="text" ng-model="IP">
                    <p class="input-group" style="margin-top:10px">
                       <input placeholder="评论开始时间" datetime-picker="yyyy-MM-dd HH:mm:ss" is-open="picker1.open" datepicker-options="datepickerOptions" class="form-control" type="text" ng-model="BeginTime">
                        <span class="input-group-btn">
                            <button type="button" class="btn btn-default" ng-click="openCalendar($event, 'picker1')"><i class="fa fa-calendar"></i></button>
                        </span>
                    </p>
                    <p class="input-group" style="margin-top:10px">
                        <input placeholder="评论结束时间" datetime-picker="yyyy-MM-dd HH:mm:ss" is-open="picker2.open" datepicker-options="datepickerOptions" class="form-control" type="text" ng-model="EndTime">
                        <span class="input-group-btn">
                            <button type="button" class="btn btn-default" ng-click="openCalendar($event, 'picker2')"><i class="fa fa-calendar"></i></button>
                        </span>
                    </p>
                    <button type="submit" class="btn btn-labeled btn-primary" ng-click="tableParams.$params.page = 1;tableParams.reload()">
                        <span class="btn-label">
                            <em class="fa fa-search"></em>
                        </span>搜索
                    </button>
                   
                </div>
            </div>
        </div>
        <div class="panel-body">
            <div class="table-responsive">
                <table ng-table="tableParams" class="table table-striped table-bproducted table-hover">
                    <tbody>
                        <tr ng-repeat="datamodel in $data">
                            <td data-title="'产品编号'" class="text-center">{{datamodel.ProductSku}}</td>
                            <td data-title="'产品名称'" class="text-center">{{datamodel.ProductName}}</td>
                            <td data-title="'满意度'" class="text-center">{{datamodel.CommentLevelDes}}</td>
                            <td data-title="'评论内容'" class="text-center">
                                <div style="-moz-word-break: break-all; -o-word-break: break-all; word-break: break-all; word-wrap: break-word;">
                                    {{datamodel.DPContent.length>50?datamodel.DPContent.substring(0,49)+'...':datamodel.DPContent}}
                                </div>
                            </td>
                            <td data-title="'评论人'" class="text-center">{{datamodel.NikName}}</td>
                            <td data-title="'评论时间'" class="text-center" sortable="'AddTime'">{{datamodel.AddTime}}</td>
                            <td data-title="'IP'" class="text-center">{{datamodel.IP}}</td>
                            <td data-title="'回复内容'" class="text-center">
                                <div style="-moz-word-break: break-all; -o-word-break: break-all; word-break: break-all; word-wrap: break-word;">
                                    {{datamodel.ReplyContent.length>50?datamodel.ReplyContent.substring(0,49)+'...':datamodel.ReplyContent}}
                                </div>
                            </td>
                            <td data-title="'回复人'" class="text-center">{{datamodel.ReplyUserName}}</td>
                            <td data-title="'回复时间'" class="text-center" sortable="'ReplyTime'">{{datamodel.ReplyTime=="1900-01-01 00:00:00"?"":datamodel.ReplyTime}}</td>
                            <td data-title="'操作'" nowrap="nowrap" class="text-center">
                                <button type="button" ng-click="UpdataView(datamodel)" class="btn btn-sm btn-edit" title="编辑">
                                    <em class="fa fa-reply"></em>
                                </button>
                                <button type="button" ng-click="removeData(datamodel)" class="btn btn-sm btn-danger" title="删除">
                                    <em class="fa fa-trash-o"></em>
                                </button>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<script type="text/ng-template" id="setUpTempDialogId">
    <div class="ngdialog-message">
        <div class="panel panel-default">
                <div class="panel-body">
                    <fieldset class="b0">
                        <legend>回复评论</legend>
                    </fieldset>
                    <fieldset>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><img src="{{Position.HeadUrl}}" class="media-object img-circle thumb64"></label>
                            <div class="col-sm-8">
                                {{Position.AddTime}}
                                <p>{{Position.DPContent}}</p>
                            </div>
                        </div>
                    </fieldset>
                    <fieldset>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"></label>
                            <div class="col-sm-8">
                                <textarea ng-model="Position.ReplyContent" class="form-control" style="height: 200px;"></textarea>
                            </div>
                        </div>
                    </fieldset>
                    
                    <div class="panel-footer text-right">
                        <button type="button" class="btn btn-default" ng-click="closeThisDialog()">
                            关闭
                        </button>
                        <button type="button" class="btn btn-default" ng-click="serveThisMessage()">
                            确定
                        </button>
                    </div>
                </div>
            </div>
    </div>
</script>
<script type="text/ng-template" id="deleteConfirmDialog">
    <div class="ngdialog-message  text-center">
        <h3>确定要删除吗?</h3>
        <p>删除后不可恢复!</p>
        <button type="button" ng-click="confirm()" class="btn btn-primary mr">确认</button>
        <button type="button" ng-click="closeThisDialog('button')" class="btn btn-default">取消</button>
    </div>
</script>
<script>
    App.controller('ProductCommentController', [
    '$scope', '$resource', '$state', '$route', '$http', 'ngTableParams', 'ngTableDataService', 'Notify', '$filter', 'ngDialog', "$stateParams", "$timeout",
        function ($scope, $resource, $state, $route, $http, ngTableParams, ngTableDataService, Notify, $filter, ngDialog, $stateParams, $timeout) {
            'use strict';
            $scope.isLoading = true;

            // 日期插件
            $scope.picker1 = {
                date: new Date()
            };

            $scope.picker2 = {
                date: new Date()
            };

            $scope.datepickerOptions = {
                showWeeks: false,
                startingDay: 1,
                dateDisabled: function (data) {
                    //return (data.mode === 'day' && (new Date().toDateString() == data.date.toDateString()));
                }
            }

            $scope.openCalendar = function (e, picker) {
                $scope[picker].open = true;
            };

            //数据查询
            $scope.tableParams = new ngTableParams({
                page: 1,
                count: 10,
                sorting: {
                    Id: 'desc'     // 初始化排序
                }
            }, {
                getData: function ($defer, params) {
                    $scope.isLoading = true;
                    var requestParams = {
                        Skip: (params.page() - 1) * params.count(),
                        Take: params.count(),
                        Keywords: $scope.Keywords,
                        Start: $scope.BeginTime,
                        End: $scope.EndTime,
                        IP:$scope.IP
                    };
                    $http.post('/Product/CommentManage', ngTableDataService.getServerSideParams(params.orderBy().toString(), params, requestParams))
                        .success(function (data, status) {
                            params.total(data.Total);
                            $defer.resolve(data.Results);
                            $scope.isLoading = false;
                        });
                }
            });

            //跳转更新新增页面
            $scope.UpdataView = function (positionCenter) {
                if (positionCenter == 0) {
                    $scope.Position = {};
                } else {
                    $scope.Position = angular.copy(positionCenter);
                }
                ngDialog.openConfirm({
                    template: 'setUpTempDialogId',
                    className: 'ngdialog-theme-plain',
                    scope: $scope
                }).then(function (value) {
                }, function (reason) {
                }
                );
            }
            //确认点击
            $scope.serveThisMessage = function () {
                $http.post("/Product/CommentReply", { comment: $scope.Position }).then(function (returnData) {
                    if (returnData.data.isSuccess) {
                        Notify.alert('操作成功!', { status: 'success' });
                        ngDialog.closeAll();
                        $scope.tableParams.$params.page = 1;
                        $scope.tableParams.reload();
                    } else {
                        Notify.alert(returnData.data.msg, { status: 'warning' });
                    }
                });
            }


            //删除
            $scope.removeData = function (positionCenter) {
                ngDialog.openConfirm({
                    template: 'deleteConfirmDialog',
                    className: 'ngdialog-theme-default',
                    scope: $scope
                }).then(function (value) {
                    $scope.isLoading = true;
                    $http.post("/Product/DelComment", { Id: positionCenter.Id }).then(function (returnData) {
                        if (returnData.data.isSuccess) {
                            Notify.alert('操作成功!', { status: 'success' });
                            $scope.tableParams.$params.page = 1;
                            $scope.tableParams.reload();
                        } else {
                            Notify.alert(returnData.data.msg, { status: 'warning' });
                        }
                        $scope.isLoading = false;
                    });
                }, function (reason) {
                }
                );
            }

        }
    ]);
</script>
